//
//  GYMineAccountInfoVC.m
//  GYDemo
//
//  Created by mac on 2018/3/23.
//  Copyright © 2018年 mac. All rights reserved.
//

//
//                .-~~~~~~~~~-._       _.-~~~~~~~~~-.
//            __.'              ~.   .~              `.__
//          .'//                  \./                  \\`.
//        .'//                     |                     \\`.
//      .'// .-~"""""""~~~~-._     |     _,-~~~~"""""""~-. \\`.
//    .'//.-"                 `-.  |  .-'                 "-.\\`.
//  .'//______.============-..   \ | /   ..-============.______\\`.
//.'______________________________\|/______________________________`.
//
//

#import "GYMineAccountInfoVC.h"
#import "Head.h"
@interface GYMineAccountInfoVC ()<ACEExpandableTableViewDelegate>
@property (nonatomic,strong) NSArray *titles;
@property (nonatomic,strong) NSArray *keys;
@property (nonatomic, assign) BOOL isEditAble;
@property (nonatomic,strong) NSString *loginmobile;
@property (nonatomic,strong) NSString *name;
@property (nonatomic,strong) NSString *qq;
@end

@implementation GYMineAccountInfoVC
#pragma mark - getter and setter
-(NSArray *)titles
{
    if (!_titles) {
        _titles = @[@"用户手机号",@"用户姓名",@"QQ号"];
    }
    return _titles;
}
-(NSArray *)keys
{
    if (!_keys) {
        _keys = @[@"loginmobile",@"name",@"qq"];
    }
    return _keys;
}
-(NSString *)loginmobile
{
    if (!_loginmobile) {
        
        if ([[GYLoginViewModel shareInterface] roleType]==1) {
            _loginmobile = [GYUserViewModel shareInterface].userModel.loginmobile;
        }else
        {
            _loginmobile=[GYStorageUserViewModel shareInterface].userModel.mobile;
        }
        
    }
    return _loginmobile;
}
-(NSString *)name
{
    if (!_name) {
        if ([[GYLoginViewModel shareInterface] roleType]==1)
        {
             _name = [GYUserViewModel shareInterface].userModel.name;
        }else
        {
             _name = [GYStorageUserViewModel shareInterface].userModel.name;
        }
       
    }
    return _name;
}
-(NSString *)qq
{
    if (!_qq) {
        if ([[GYLoginViewModel shareInterface] roleType]==1)
        {
            _qq = [GYUserViewModel shareInterface].userModel.qq;
        }else
        {
            _qq = [GYStorageUserViewModel shareInterface].userModel.qq;
        }
    }
    return _qq;
}
#pragma mark - event
#pragma mark - method
-(void)initilization
{
    self.navigationItem.title = @"账户信息";
    self.automaticallyAdjustsScrollViewInsets = NO;
    self.edgesForExtendedLayout = UIRectEdgeNone;
    
    self.navigationController.navigationBar.shadowImage = [[UIImage new]rt_darkenWithLevel:0.3f];
    [self setNavgationTheme:1];
    [self.view addSubview:self.baseTable];
    [self.baseTable setSeparatorStyle:UITableViewCellSeparatorStyleSingleLine];
    [self.baseTable setSeparatorColor: Main_Color_BG];
    [self.baseTable setBackgroundColor:Main_Color_BG];
    [self.baseTable setTintColor:Main_Color_BG];
    if (@available(iOS 11.0, *)) {
        //        self.baseTable.contentInset = UIEdgeInsetsMake(-64, 0, 0, 0);
    }
    self.baseTable.mj_header.backgroundColor = Main_Color_Red;
    NSLog(@"%f",self.view.height);
    NSLog(@"%f",self.baseTable.height);
    self.baseTable.scrollIndicatorInsets = self.baseTable.contentInset;
    [self viewModelBand];
   // [self judgeValue];
}
-(void)viewModelBand
{
    @WeakSelf;
    GCBaseObservationModel *observation = [GCBaseObservationModel new];
    observation.observation =[[GYLoginViewModel shareInterface] roleType]==1?[GYUserViewModel shareInterface]:[GYStorageUserViewModel shareInterface];
    observation.keyPath = @"userModel";
    observation.handler = ^(NSString *keyPath) {
        [selfp reloadView];
        [selfp.navigationController popViewControllerAnimated:YES];
    };
    [self registObservation:observation];
}
-(void)reloadView
{
    [self.baseTable reloadData];
}
-(void)reloadData
{
    
}

- (void)judgeValue {
    
    @WeakSelf;;
    [self setRightBarButtonWithTitle:@"修改" titleColor:Main_Color_Black withBlock:^() {
        selfp.baseTable.userInteractionEnabled = YES;
        _isEditAble = YES;
        [selfp.baseTable reloadData];
        
        [selfp setRightBarButtonWithTitle:@"完成" titleColor:Main_Color_Black withBlock:^() {
            selfp.baseTable.userInteractionEnabled = NO;
            _isEditAble = NO;
            [selfp.baseTable reloadData];
            
            NSMutableDictionary *para = [NSMutableDictionary new];
            NSString *name = [selfp valueForKey:@"name"] ?: @"";
            NSString *qq = [selfp valueForKey:@"qq"] ?: @"";
            [para setObject:name forKey:@"name"];
            [para setObject:qq forKey:@"qq"];
            if ([[GYLoginViewModel shareInterface] roleType]==1)
            {
                [[GYUserViewModel shareInterface]requestUpdateUserInfo:para];
            }else
            {
                [[GYStorageUserViewModel shareInterface]requestUpdateUserInfo:para];
            }
            
        }];
    }];
    
}
#pragma mark - life
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self initilization];
}

-(void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
//    [self setNavgationTheme:1];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
 #pragma mark - Navigation
 
 // In a storyboard-based application, you will often want to do a little preparation before navigation
 - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
 // Get the new view controller using [segue destinationViewController].
 // Pass the selected object to the new view controller.
 }
 */
#pragma mark - delegate
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.titles.count;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return WFCGFloatY(45);
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString *CellID = @"CellID";
    GYExpandableCell *cell = [tableView dequeueReusableCellWithIdentifier:CellID];
    if (!cell) {
        cell = [[GYExpandableCell alloc]initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:CellID];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        cell.expandableTableView = tableView;
    }
    cell.titleLB.text = self.titles[indexPath.row];
    
    if (indexPath.row==0) {
        cell.textView.text =[GYLoginViewModel shareInterface].loginInfoModel.mobile;
    }
    if (indexPath.row==1) {
        cell.textView.text = [GYLoginViewModel shareInterface].loginInfoModel.nick_name;
    }
    if (indexPath.row==2) {
        cell.textView.text = [GYLoginViewModel shareInterface].loginInfoModel.storeid;
    }
    
    cell.textView.editable =NO;
    return cell;
}
-(void)tableView:(UITableView* )tableView willDisplayCell:(UITableViewCell* )cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
    [cell setSeparatorInset:UIEdgeInsetsMake(0, WFCGFloatX(13), 0, 0)];
    [cell setLayoutMargins:UIEdgeInsetsZero];
}
#pragma mark - ace delegate
- (void)tableView:(UITableView *)tableView updatedText:(NSString *)text atIndexPath:(NSIndexPath *)indexPath {
    NSString *key = self.keys[indexPath.row];
    [self setValue:text forKey:key];
}
@end


/*
 11111111111111111111111111111111111111001111111111111111111111111
 11111111111111111111111111111111111100011111111111111111111111111
 11111111111111111111111111111111100001111111111111111111111111111
 11111111111111111111111111111110000111111111111111111111111111111
 11111111111111111111111111111000000111111111111111111111111111111
 11111111111111111111111111100000011110001100000000000000011111111
 11111111111111111100000000000000000000000000000000011111111111111
 11111111111111110111000000000000000000000000000011111111111111111
 11111111111111111111111000000000000000000000000000000000111111111
 11111111111111111110000000000000000000000000000000111111111111111
 11111111111111111100011100000000000000000000000000000111111111111
 11111111111111100000110000000000011000000000000000000011111111111
 11111111111111000000000000000100111100000000000001100000111111111
 11111111110000000000000000001110111110000000000000111000011111111
 11111111000000000000000000011111111100000000000000011110001111111
 11111110000000011111111111111111111100000000000000001111100111111
 11111111000001111111111111111111110000000000000000001111111111111
 11111111110111111111111111111100000000000000000000000111111111111
 11111111111111110000000000000000000000000000000000000111111111111
 11111111111111111100000000000000000000000000001100000111111111111
 11111111111111000000000000000000000000000000111100000111111111111
 11111111111000000000000000000000000000000001111110000111111111111
 11111111100000000000000000000000000000001111111110000111111111111
 11111110000000000000000000000000000000111111111110000111111111111
 11111100000000000000000001110000001111111111111110001111111111111
 11111000000000000000011111111111111111111111111110011111111111111
 11110000000000000001111111111111111100111111111111111111111111111
 11100000000000000011111111111111111111100001111111111111111111111
 11100000000001000111111111111111111111111000001111111111111111111
 11000000000001100111111111111111111111111110000000111111111111111
 11000000000000111011111111111100011111000011100000001111111111111
 11000000000000011111111111111111000111110000000000000011111111111
 11000000000000000011111111111111000000000000000000000000111111111
 11001000000000000000001111111110000000000000000000000000001111111
 11100110000000000001111111110000000000000000111000000000000111111
 11110110000000000000000000000000000000000111111111110000000011111
 11111110000000000000000000000000000000001111111111111100000001111
 11111110000010000000000000000001100000000111011111111110000001111
 11111111000111110000000000000111110000000000111111111110110000111
 11111110001111111100010000000001111100000111111111111111110000111
 11111110001111111111111110000000111111100000000111111111111000111
 11111111001111111111111111111000000111111111111111111111111100011
 11111111101111111111111111111110000111111111111111111111111001111
 11111111111111111111111111111110001111111111111111111111100111111
 11111111111111111111111111111111001111111111111111111111001111111
 11111111111111111111111111111111100111111111111111111111111111111
 11111111111111111111111111111111110111111111111111111111111111111
 
 
 */
